#include <stdio.h>
#include "dclcd.h"
#include "tskcfg.h"
#include "bsp.h"
#include "parameter.h"
#include <stdlib.h>

#define MESSAGE_SHOW_TIMEOUT_S         15

static void ok(void);
static void load(uint8_t nowpage, uint8_t nowfocus);
static void update(uint8_t keyvalue);

static const uint32_t message_show_timeout = 1000;
static uint8_t timeout;

const static GUI_FormKeysStru gui_calmessage_keys = 
{
	.mute =   NULL,
	.power =  NULL,
  .keyt =   NULL,
  .set =    NULL,
  .home =   gui_form_common_home,
  .menu =   NULL,
  .keyret = ok,
  .enter =  NULL,
	.down =   NULL,
	.up =     NULL,
	.left =   NULL,
	.right =  NULL,
	.ok =     ok,
	.volinc = NULL,
	.voldec = NULL,
	.key0 =   NULL,
	.key1 =   NULL,
	.key2 =   NULL,
	.key3 =   NULL,
	.key4 =   NULL,
	.key5 =   NULL,
	.key6 =   NULL,
	.key7 =   NULL,
	.key8 =   NULL,
	.key9 =   NULL,
};

const GUI_FormStru gui_from_calmessage = 
{
	.load    = load,
	.update  = update,
	.keys    = &gui_calmessage_keys,
  .refresh = &message_show_timeout,
};

static void load(uint8_t nowpage, uint8_t nowfocus)
{
  timeout = 0;
  dc_load_calmessage(nowpage,0);
}

static void update(uint8_t keyvalue)
{
  if(timeout++ >= MESSAGE_SHOW_TIMEOUT_S)
  {
    timeout = 0;
    gui_form_exec(&gui_from_calimenu, 0, 0);
  }
}

static void ok(void)
{
	gui_form_exec(&gui_from_calimenu, 0, 0);
}
